package cn.edu.xmu.javaee.springsecurity.service;



import cn.edu.xmu.javaee.springsecurity.dao.ProductDao;
import cn.edu.xmu.javaee.springsecurity.dao.bo.ProductDraft;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class ProductService {

    private final ProductDao productDao;

    public ProductDraft createDraft(ProductDraft draft){
        return this.productDao.insert(draft);
    }

    public ProductDraft getDraft(Long shopId, Long draftId){
        ProductDraft draft = this.productDao.findById(shopId, draftId);
        log.debug("getDraft: draft = {}", draft);
        return draft;
    }

    public void delDraft(Long shopId, Long draftId){
        this.productDao.findById(shopId, draftId);
        this.productDao.deleteById(draftId);
    }

    public void updateDraft(Long shopId, ProductDraft draft){
        this.productDao.findById(shopId, draft.getId());
        this.productDao.updateById(draft);
    }
}
